package com.example._03vehicle.base.interceptors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

@Slf4j
public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
        log.debug("进入限定时间的拦截器");
        LocalTime localTime = LocalTime.now();
        if(localTime.isAfter(LocalTime.of(8,0))&&localTime.isBefore(LocalTime.of(20,0))){
            log.debug("当前时间在8:00-20:00之间");
            return true;
        }else {
            log.debug("当前时间不在8:00-20:00之间");
            return false;
        }
    }
}
